import { defineStore } from "pinia";
import { computed, ref } from "vue";

/* defineStore(仓库的唯一标识，()=>{}) */
export const useCounterStore =  defineStore('counter',()=>{
    //声明数据 state
    const count = ref(100)
    const msg = ref('hello pinia')
    const addCount = () => count.value++
    const subCount = () => count.value--
    //声明基于数据派生的计算属性 getters （computed）
    const double = computed(() => count.value*2)
    return{
        count,
        msg,
        double,
        addCount,
        subCount
    }
},{
    //开启当前模块的持久化
   /*  persist:true */
   persist:{
    key:'sum-counter',
    pick:['count']

   }
})